<template>
	<view class="recruit-index">
		<view class="recruit-list" :style="{opacity:resumeids.indexOf(item.id)>-1?'0.5':'1'}"
			v-for="(item,index) in resumeList" :key="index" @click="jump(item)">
			<view class="item1">
				<view class="status">
					<view class="name">
						{{item.name}}
					</view>
					<view class="value">
						{{item.date}}岁 ·
						{{item.age.title ? item.age.title : item.age}} ·
						{{item.areas.title ? item.areas.title: item.areas}}
					</view>
				</view>
				<image :src="item.head" mode=""></image>
			</view>
			<view class="item2">
				<view class="position">
					服务技能：{{item.types.join(',')}}
				</view>
				<view class="time">
					{{item.refresh}}
				</view>
			</view>
		</view>
		<empty v-if="total==0" :text='text' />
		<uni-load-more :status="status" v-if="status && total!=0"></uni-load-more>
		<uni-popup ref="popup" type="center">
			<view class="tips">
				<view class="title">
					提示
				</view>
				<view class="value">
					<text v-if="isVip==0">查看牛人上限，观看广告继续查看</text>
				<!-- 	<text v-if="isVip==0">查看牛人上限，开通VIP继续查看</text>
					<text v-if="isVip==1">查看牛人上限</text>
					<text v-if="isVip==2">会员已过期</text> -->
				</view>
				<view class="share-box" v-if="isVip!=1">
					<view class="close" @click="close()">
						取消
					</view>
					<view class="goshare" >
						<!-- #ifndef APP-PLUS -->
						<button >关闭</button>
						 <!-- #endif -->
						<!-- #ifdef APP-PLUS -->
						<ad-rewarded-video adpid="1535676075" :url-callback="urlCallback" :loadnext="true" v-slot:default="{loading, error}" @close="onadclose" @load="onadload" @error="onaderror">
						      <button :disabled="loading" >观看广告</button>
						      <view v-if="error">{{error}}</view>
						</ad-rewarded-video>
						 <!-- #endif -->
					</view>
				</view>
				<view class="share-box" v-else>
					<view class="close" style="width: 100%;" @click="close()">
						关闭
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import * as user from '@/api/user.js'
	import * as index from '@/api/index.js'
	import empty from '@/components/empty/index.vue'
	export default {
		props: {
			resumeList: Array,
			userInfos: Object,
			Type: Number,
			text: String,
			total: Number,
			status: String
		},
		components: {
			empty
		},
		name: "recruit",
		data() {
			return {
				 urlCallback: {
					userId: 'testuser',
					extra: 'testdata'
				  },
				userInfo: this.userInfos,
				resumeids: [],
				isVip: 0,
				resume_forward:'',
			};
		},
		mounted() {
			this.nameGetConfig()
			if (uni.getStorageSync('token')) {
				user.getUserInfo({
					type: uni.getStorageSync('Type')
				}).then(res => {
					this.userInfo = res.data
					this.resumeids = res.data.resumeids.map(Number)
				})
			}
		},
		methods: {
			// 获取分享图片
			nameGetConfig() {
				index.nameGetConfig({name:'wx_share_image,company_vip_resume'}).then(res=>{
					this.resume_forward = res.data.company_vip_resume
				})
			},
			// 去开通vip
			goBnt() {
				this.$tools.navigate(`/pages/user/vip/index`)
				this.$refs.popup.close()
			},
			close() {
				this.$refs.popup.close()
			},
			onadload(e) {
			  console.log('广告数据加载成功');
			},
			onadclose(e) {
			  const detail = e.detail
			  // 用户点击了【关闭广告】按钮
			  if (detail && detail.isEnded) {
				// 正常播放结束
				console.log("onadclose " + detail.isEnded);
				index.wxForwardGetAward({type:1}).then(res=>{
					this.$refs.popup.close()
					uni.showToast({
						icon: 'none',
						title: `查看接单已+${this.resume_forward}条,\n感谢您助力鱼台就业。`,
						duration: 2000
					});
					// this.$tools.navigate(`/pages/home/resumeInfo/index?resume_id=${item.member_id}`)
				})
			  } else {
				// 播放中途退出
				console.log("onadclose " + detail.isEnded);
			  }
			},
			onaderror(e) {
			  // 广告加载失败
			  console.log("onaderror: ", e.detail);
			},
			jump(item) {
				user.getUserInfo({
					type: uni.getStorageSync('Type')
				}).then(res => {
					this.userInfo = res.data
					var time = Math.round(new Date().getTime() / 1000).toString();
					if (res.data.company_vip == 0) {
						this.isVip = 0
					} else if (time < res.data.company_vip) {
						this.isVip = 1
					} else {
						this.isVip = 2
					}
					if (res.data.company == 1) {
						if (res.data.visual_upper_limit <= res.data.company_resume && res.data.resumeids.map(
								Number).indexOf(item.id) < 0) {
							this.$refs.popup.open()
							// this.resumeids.push(item.id)
							// index.wxForwardGetAward({type:1}).then(res=>{
							// 	this.$tools.navigate(`/pages/home/resumeInfo/index?resume_id=${item.member_id}`)
							// })
						} else {
							this.resumeids.push(item.id)
							this.$tools.navigate(`/pages/home/resumeInfo/index?resume_id=${item.member_id}`)
						}
					} else {
						this.$tools.toast('雇主未审核通过')
					}

				})
			},
		}
	}
</script>

<style lang="scss">
	.recruit-index {
		padding: 5rpx 20rpx;

		.recruit-list {
			background: #ffffff;
			padding: 41rpx 48rpx;
			margin-bottom: 12rpx;

			.item1 {
				display: flex;
				justify-content: space-between;

				.status {
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.name {
						font-size: 32rpx;
						font-weight: 700;
						color: #333333;
						line-height: 45rpx;
					}

					.value {
						font-size: 28rpx;
						font-weight: 500;
						color: #333333;
						line-height: 40rpx;
					}
				}

				image {
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
				}
			}

			.item2 {
				display: flex;
				justify-content: space-between;
				margin-top: 18rpx;

				.position {
					font-size: 26rpx;
					font-weight: 400;
					color: #9E9E9E;
					line-height: 37rpx;
					text-overflow: ellipsis;
					white-space: nowrap;
					overflow: hidden;
				}

				.time {
					flex-shrink: 0;
					font-size: 24rpx;
					font-weight: 400;
					color: #999999;
					line-height: 33rpx;
				}
			}
		}

		.tips {
			width: calc(100vw - 190rpx);
			background: #ffffff;
			border-radius: 16rpx;

			.title {
				font-size: 36rpx;
				font-weight: 700;
				color: #202020;
				line-height: 54rpx;
				padding: 40rpx 40rpx 16rpx;
			}

			.value {
				margin-top: 16rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #202020;
				padding: 0rpx 40rpx 40rpx;
			}

			.share-box {
				display: flex;
				justify-content: space-between;
				border-top: 2rpx solid rgba(196, 196, 196, 0.2);
				;

				.close {
					width: 50%;
					text-align: center;
					padding: 40rpx 0;
					border-right: 2rpx solid rgba(196, 196, 196, 0.2);
					;
					font-size: 32rpx;
					font-weight: 400;
					color: #202020;
				}

				.goshare {
					width: 50%;
					text-align: center;
					padding: 40rpx 0;
					font-size: 32rpx;
					font-weight: 700;
					color: #FF6600;
					position: relative;

					button::after {
						border: none;
					}
					button::after{
					 	border: none;
					}
					button{
						position: relative;
						display: block;
						margin-left: auto;
						margin-right: auto;
						padding-left: 0px;
						padding-right: 0px;
						box-sizing: border-box;
						// font-size: 18px;
						text-align: center;
						text-decoration: none;
						// line-height: 1;
						line-height: 1.35;
						// border-radius: 5px;
						-webkit-tap-highlight-color: transparent;
						overflow: hidden;
						color: #FF6600;
						background-color: #fff;
						width: 100%;
						height: 100%;
						}
					.bnt {
						position: absolute;
						width: 100%;
						height: 100%;
						top: 0;
						left: 0;
						opacity: 0;
						z-index: 999;
					}
				}
			}
		}
	}
</style>
